<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\common\command;


use app\common\model\book\Book;
use app\common\model\bookpack\Bookpack;
use app\common\model\bookpack\BookpackAssociation;
use app\common\model\buy\EgoldCountLog as EgoldCountLogModel;
use app\common\model\buy\EgoldLog as EgoldLogModel;
use app\common\model\user\User as UserModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;


class UpdateBookpackBook extends Command
{
    protected function configure()
    {
        $this->setName('update_bookpack_book')
            ->setDescription('赠币过期作废');
    }


    protected function execute(Input $input, Output $output)
    {
        try {
            $time = time();
            $book_list = Book::where('status',1)->select();
            $bookpackList = Bookpack::where('status',1)->select();
            BookpackAssociation::where(1,1)->delete();
            $insertArr = [];
            foreach ($bookpackList as $k=>$v){
                $arr = [];
                foreach ($book_list as $key=>$value){
                    $arr['book_id'] = $value['id'];
                    $arr['bookpack_id'] = $v['id'];
                    $arr['sort'] = 0;
                    $arr['create_time'] = $time;
                    $arr['update_time'] = $time;
                    $insertArr[] = $arr;
                }
            }
            BookpackAssociation::insertAll($insertArr);
            $output->writeln('书包书籍修改成功');
            return true;
        } catch (\Exception $e) {
            Log::write('书包书籍处理失败,失败原因:' . $e->getMessage());
            return false;
        }
    }

}